package com.google.code.yargon.engine;

import com.google.code.yargon.level.*;
import com.google.code.yargon.ui.component.Refreshable;

public class Creature implements CreatureIf, Refreshable {
	
	private Location l;
	private boolean refresh = false;
	
	@Override
	public Location getLocation() {
		return l;
	}
	
	@Override
	public void setLocation(Location l) {
		this.l = l;
	}
	
	@Override
	public void move(LevelArea level) {
		
		Direction rd = Direction.getRandomDirection();
		
		if(level.isFloor(l.toDirection(rd)) || level.isTunnel(l.toDirection(rd))) {
			l.moveTo(rd);
		} 
		else if(level.isDoor(l.toDirection(rd)) && (((DoorBlock)level.get(l.toDirection(rd))).isOpen() || ((DoorBlock)level.get(l.toDirection(rd))).getDurability() == 0)) {
			l.moveTo(rd);
		}		
	}

	@Override
	public void setRefresh(boolean refresh) {
		this.refresh = refresh;
	}

	@Override
	public boolean needRefresh() {
		return this.refresh;
	}
}
